package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.Email;
import com.acme.bankapp.domain.bank.EmailQueue;

/**
 * Created by anton on 8/25/14.
 */
public class EmailService {

    private EmailQueue eq = new EmailQueue();

    public EmailService() {
        Thread t = new Thread(() -> {
//            System.out.println("aaaa");
           while (!(eq.isClosed() && eq.isEmpty())) {
               Email e = eq.remove();
               System.out.println("~~~~~~~~~~~~~~~~~~~~~");
               System.out.println("Notification email for client " + e.getClient().getName() + " at " + e.getEmail() + " to be sent");
           }
        });
        t.start();
    }


    public void sendNotificationEmail(Client client, String email) {
        eq.add(new Email(client, email));
    }

    public void close() {
        eq.closeAdding();
    }

}
